package cursor;

import java.awt.Component;
import java.awt.Cursor;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public final class CursorController {

	public final static Cursor busyCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
	public final static Cursor defaultCursor = Cursor.getDefaultCursor();

	private CursorController() {}

	public static ActionListener createListener(final Component component, final ActionListener mainActionListener) {
		ActionListener actionListener = new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				try {
					component.setCursor(busyCursor);
					mainActionListener.actionPerformed(ae);
				} finally {
					component.setCursor(defaultCursor);
				}
			}
		};
		return actionListener;
	}
	
	public static MouseListener createListener(final Component component, final MouseListener mainMouseListener) {
		MouseListener mouseListener = new MouseListener() {
			@Override
			public void mouseClicked(MouseEvent e) {
				try {
					component.setCursor(busyCursor);
					mainMouseListener.mouseClicked(e);
				} finally {
					component.setCursor(defaultCursor);
				}
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				
			}

			@Override
			public void mouseExited(MouseEvent e) {
				
			}

			@Override
			public void mousePressed(MouseEvent e) {
				
			}

			@Override
			public void mouseReleased(MouseEvent e) {
				
			}
		};
		return mouseListener;
	}
}
